#import "Character.h"


@implementation Character

@synthesize name;
@synthesize health;
@synthesize speed;
@synthesize damage;
@synthesize weaponSpeed;
@synthesize currentHealth;
@synthesize score;
@synthesize healthModifier;
@synthesize image;
@synthesize shellImage;
@synthesize good;
@synthesize level;
@synthesize imageView;
@synthesize animationImages;
@synthesize shellShotSound;
@synthesize rank;
@synthesize sprite;
@synthesize animationCharacter;

- (void)encodeWithCoder: (NSCoder *) encoder {
	[encoder encodeObject:self.name forKey:@"name"];
	[encoder encodeFloat:self.health forKey:@"health"];
	[encoder encodeFloat:self.speed forKey:@"speed"];
	[encoder encodeFloat:self.damage forKey:@"damage"];
	[encoder encodeFloat:self.weaponSpeed forKey:@"weaponSpeed"];
	[encoder encodeFloat:self.currentHealth forKey:@"currentHealth"];
	[encoder encodeFloat:self.score forKey:@"score"];
	[encoder encodeFloat:self.healthModifier forKey:@"healthModifier"];
	[encoder encodeBool:self.good forKey:@"good"];
	[encoder encodeInt:self.level forKey:@"level"];
	[encoder encodeInt:self.rank forKey:@"rank"];
}

- (id)initWithCoder: (NSCoder *) decoder {
	if (self = [self initWithName:[decoder decodeObjectForKey:@"name"] isGood:[decoder decodeBoolForKey:@"good"]]) {
		self.health = [decoder decodeFloatForKey:@"health"];
		self.speed = [decoder decodeFloatForKey:@"speed"];
		self.damage = [decoder decodeFloatForKey:@"damage"];
		self.weaponSpeed = [decoder decodeFloatForKey:@"weaponSpeed"];
		self.currentHealth = [decoder decodeFloatForKey:@"currentHealth"];
		self.score = [decoder decodeFloatForKey:@"score"];
		self.healthModifier = [decoder decodeFloatForKey:@"healthModifier"];
		self.level = [decoder decodeIntForKey:@"level"];
		self.rank = [decoder decodeIntForKey:@"rank"];
	}
	
	return self;
}

- (id)initWithName:(NSString *)characterName isGood:(BOOL)isGood {
	if (self == [super init]) {
		self.name = characterName;
		self.health = 0;
		self.speed = 0;
		self.damage = 0;
		self.weaponSpeed = 0;
		self.score = 0;
		self.currentHealth = 0;
		self.image = nil;
		self.shellImage = nil;
		self.good = isGood;
		self.level = 1;		
		self.animationImages = nil;
		//self.shellShotSound = 0;
		self.healthModifier = 1.0;
		
//		sprite = [[Sprite alloc] initWithFileNamed:@"TestCharSprite.png"];
//		sprite.size = Vector3Make(32, 32, 0);
		
		[BoardCharSprite setDefaultSize:Vector3Make(32, 32, 0)];
		[BoardCharSprite setDefaultFrameSize:Vector3Make(64, 64, 0)];
		[BoardCharSprite setDefaultHotspot:Vector3Make(16, 0, 32)];

		sprite  = [BoardCharSprite alloc];
		
		if ([name isEqualToString:@"Warrior"]) {
			self.image = [UIImage imageNamed:@"Cerberus1.png"];
			self.shellImage = [UIImage imageNamed:@"14.png"];
			//self.shellShotSound = appDelegate.shot1314;
			self.rank = 7;
//			self.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Cerberus1.png"], [UIImage imageNamed:@"Cerberus2.png"],
//									[UIImage imageNamed:@"Cerberus3.png"], [UIImage imageNamed:@"Cerberus4.png"],
//									[UIImage imageNamed:@"Cerberus5.png"], [UIImage imageNamed:@"Cerberus6.png"],
//									[UIImage imageNamed:@"Cerberus7.png"], [UIImage imageNamed:@"Cerberus8.png"],
//									[UIImage imageNamed:@"Cerberus9.png"], [UIImage imageNamed:@"Cerberus10.png"],
//									[UIImage imageNamed:@"Cerberus11.png"], [UIImage imageNamed:@"Cerberus12.png"],
//									[UIImage imageNamed:@"Cerberus13.png"], [UIImage imageNamed:@"Cerberus14.png"],
//									[UIImage imageNamed:@"Cerberus15.png"], [UIImage imageNamed:@"Cerberus16.png"], 
//									[UIImage imageNamed:@"Cerberus17.png"], [UIImage imageNamed:@"Cerberus18.png"], 
//									[UIImage imageNamed:@"Cerberus19.png"], [UIImage imageNamed:@"Cerberus20.png"],
//									[UIImage imageNamed:@"Cerberus21.png"], [UIImage imageNamed:@"Cerberus22.png"],
//									[UIImage imageNamed:@"Cerberus23.png"], [UIImage imageNamed:@"Cerberus24.png"],
//									[UIImage imageNamed:@"Cerberus25.png"], [UIImage imageNamed:@"Cerberus26.png"],
//									[UIImage imageNamed:@"Cerberus27.png"], nil];

			//[sprite initWithFileNamed:@"Cerberus1-Test-3D.png"];
			//[sprite initWithFileName:@"cerberus_3D.png" FramesCount:27 FramesPerLine:8];
			
			[BoardCharSprite setDefaultFrameSize:Vector3Make(128, 128, 0)];
			
			// Other things like before
			[BoardCharSprite setDefaultSize:Vector3Make(32, 32, 0)];
			[BoardCharSprite setDefaultHotspot:Vector3Make(16, 0, 32)];
			[sprite initWithFileName:@"Cerberys_3D_Big.png" FramesCount:27 FramesPerLine:8];
			sprite.afterRotateHotspot = Vector3Make(-16, -16, 0);
			sprite.play = NO;
			
			return self;
		}
		
		if ([name isEqualToString:@"Ghoul"]) {
			self.image = [UIImage imageNamed:@"Ogre1.png"];
			self.shellImage = [UIImage imageNamed:@"8.png"];
			//self.shellShotSound = appDelegate.shot78;
			self.rank = 4;
//			self.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Ogre1.png"], [UIImage imageNamed:@"Ogre2.png"],
//									[UIImage imageNamed:@"Ogre3.png"], [UIImage imageNamed:@"Ogre4.png"],
//									[UIImage imageNamed:@"Ogre5.png"], [UIImage imageNamed:@"Ogre6.png"],
//									[UIImage imageNamed:@"Ogre7.png"], [UIImage imageNamed:@"Ogre8.png"],
//									[UIImage imageNamed:@"Ogre9.png"], [UIImage imageNamed:@"Ogre10.png"],
//									[UIImage imageNamed:@"Ogre11.png"], [UIImage imageNamed:@"Ogre12.png"],
//									[UIImage imageNamed:@"Ogre13.png"], [UIImage imageNamed:@"Ogre14.png"],
//									[UIImage imageNamed:@"Ogre15.png"], [UIImage imageNamed:@"Ogre16.png"], 
//									[UIImage imageNamed:@"Ogre17.png"], nil];
			
			//[sprite initWithFileNamed:@"Ogre1-Test-3D.png"];
			//[sprite initWithFileName:@"Ogre_3D.png" FramesCount:17 FramesPerLine:8];
			
			[BoardCharSprite setDefaultFrameSize:Vector3Make(128, 128, 0)];
			
			// Other things like before
			[BoardCharSprite setDefaultSize:Vector3Make(32, 32, 0)];
			[BoardCharSprite setDefaultHotspot:Vector3Make(16, 0, 32)];
			[sprite initWithFileName:@"Ogre_3D_Big.png" FramesCount:16 FramesPerLine:4];
			sprite.afterRotateHotspot = Vector3Make(-16, -16, 0);
			sprite.play = NO;
			
			return self;
		}
	}

	assert(sprite!=nil);
	
	sprite.size = Vector3Make(32, 32, 0);
	//sprite.hotspot = Vector3Make(16-16, -16, 32);	// -16,-16 to place char at the center off cell
	sprite.hotspot = Vector3Make(16, 0, 32);	// -16,-16 to place char at the center off cell
	sprite.afterRotateHotspot = Vector3Make(-16, -16, 0);
	sprite.play = NO;
	//[sprite setFrame:0];
	
	return self;
}

- (void)dealloc {
	[sprite release];
	[name release];
	[image release];
	[animationImages release];
	[imageView release];
	[super dealloc];
}

@end
